package com.timer.taskRule;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

import com.timer.taskRule.entity.Role;

public class PSVM {

    public static void main(String[] args) {

        String name = "张三";
        // \u000dname="李四";
        System.out.println(name);
    }

    public void hibernateInSplit(){
         List<Role> roles = new ArrayList<>();
        Role role = new Role();
        role.setRoleName("张三");
        roles.add(role);
        Role role2 = new Role();
        role2.setRoleName("李四");
        roles.add(role2);

        AtomicReference<String> name = new AtomicReference<>();
        List<String> roleNames = roles.stream().map(Role::getRoleName).collect(Collectors.toList());
        Optional.ofNullable(roleNames).filter(u -> u.size() > 0).ifPresent(u -> {
            name.lazySet(String.format("'%s'",String.join("','",roleNames)));
        });

        System.out.println(name);
    }

    public static class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }

    public static ListNode deleteDuplicates(ListNode head) {
        if(head == null || head.next == null){
            return head;
        }
        head.next = deleteDuplicates(head.next);
        if(head.val == head.next.val) head = head.next;
        return head;
    }


    private static void matchFileName(String fileName, String matchName){
        //校验报送机构编码
        String fileReportCompany = fileName.substring(fileName.indexOf("-") + 1, fileName.indexOf("_"));
        String matchReportCompany = matchName.substring(matchName.indexOf("-") + 1, matchName.indexOf("_"));
        System.out.println(fileReportCompany + "/////" + matchReportCompany);
        System.out.println(fileReportCompany.equals(matchReportCompany));

        String[] fileNameArray = fileName.split("_");
        String[] matchNameArray = matchName.split("_");

        //接口编码
        System.out.println(fileNameArray[7]);
        System.out.println(fileNameArray[4]);

        //
    }

    /***
     * 阶乘
     */
    private static int orderOfMagnitude(int num){
        if(num == 1){
            return 1;
        }else{
            return num * orderOfMagnitude(--num);
        }
    }

    /***
     * 递归一个文件夹下的所有文件
     * @param fileDirectory
     * @return
     */
    private static int listAllFile(File fileDirectory){
        File[] files = fileDirectory.listFiles();
        int i = 0;
        for (File file : files) {
            if(file.isDirectory()){
                i += listAllFile(file);
            }else{
                System.out.println(file.getName());
                i++;
            }
        }

        return i;
    }

    public static String bytesToHexString(byte[] src) {
        StringBuilder stringBuilder = new StringBuilder("");
        if (src == null || src.length <= 0) {
            return null;
        }
        for (int i = 0; i < src.length; i++) {
            int v = src[i] & 0xFF;
            String hv = Integer.toHexString(v);
            if (hv.length() < 2) {
                stringBuilder.append(0);
            }
            stringBuilder.append(hv);
        }
        return stringBuilder.toString();
    }
}
